//
//  ActivityDetailViewController.m
//  TravelFollowYourHeart
//
//  Created by ENERGY on 2017/12/22.
//  Copyright © 2017年 Lwx. All rights reserved.
//

#import "ActivityDetailViewController.h"
#import "ActivityDetailTableViewCell.h"
#import "BookingInformationViewController.h"
#import "CRMediaPickerController.h"
#import <AVFoundation/AVFoundation.h>
#import <AVKit/AVKit.h>
#import "ActivityDetailModel.h"
#import <WebKit/WebKit.h>
#import "CustomMadeCell.h"
#import "AdModel.h"
#define border 10
#define headImageH 200
#define labelH 20
#define bottomBarH 50

@interface ActivityDetailViewController ()<ActivityDetailCellDelegate, UITableViewDelegate, UITableViewDataSource,CRMediaPickerControllerDelegate,WKNavigationDelegate, WKUIDelegate, UIScrollViewDelegate, UIGestureRecognizerDelegate, UIWebViewDelegate>
@property (nonatomic, strong)UITableView * tableView;
@property (nonatomic, strong)UIImageView * headImage;
@property (nonatomic, strong)UIView * topView;
@property (nonatomic, strong)UILabel * activityNameLab;
@property (nonatomic, strong)UILabel * moneyLab;
@property (nonatomic, strong)UIView * footView;
@property (nonatomic, strong)UILabel * firstSectionLabel;
@property (nonatomic, strong)UILabel * secondSectionLabel;
@property (nonatomic, strong)UIImageView * detailImage;
@property (nonatomic, strong)UIImageView * adImage;
@property (nonatomic, strong)UIView * bottomBarView;
@property (nonatomic, strong)UIButton * collectBtn;
@property (nonatomic, strong)UIButton * serviceBtn;
@property (nonatomic, strong)UIButton * addTravelBtn;
@property (nonatomic, strong)UILabel * activityContentLab;
@property (nonatomic, strong)UILabel * orderContentLab;
@property (nonatomic, strong)UILabel * orderPriceLab;
@property (nonatomic, strong)UIImageView * videoImage;
@property (nonatomic, strong)UIButton * videoImageBtn;
@property (nonatomic, strong)WKWebView * activityWeb;
@property (nonatomic, strong)UILabel * activityTitleLab;//活动详情
@property (nonatomic, strong)UILabel * orderTitleLab;//套餐预定
@property (nonatomic, strong)UIButton * orderBtn;//预定按钮
@property (nonatomic, strong)UIView * activityLineView;//分割线
@property (nonatomic, strong)CRMediaPickerController *mediaPickerController;
@property (nonatomic, strong)ActivityDetailModel * model;
@property (nonatomic, strong)AdModel * adModel;
@end

@implementation ActivityDetailViewController(Networking)
- (void)getActivityDetail{
    NSDictionary * dic = @{
                           @"aid":@(self.activityId),
                           @"mid":[UserModel intance].member_id,
                           };
    WS(ws)
    [self showprogressHUD];
    [[HttpRequest shardWebUtil] postNetworkRequestURLString:Url(@"/activity/activityDetail") andParas:dic andTransferGottenData:^(id obj, NSError *error) {
        [self hiddenProgressHUD];
        if (error) {
            [[HUDHelper sharedInstance] tipMessage:obj[@"msg"]];
        }else{
            if ([obj[@"code"] integerValue] == 100000){
                ws.model = [ActivityDetailModel yy_modelWithDictionary:obj[@"data"]];
                if ([ws.model.is_collect isEqualToString:@"未收藏"]) {
                    ws.collectBtn.selected = NO;
                }else{
                    ws.collectBtn.selected = YES;
                }
                ws.moneyLab.text = [NSString stringWithFormat:@"%@元", ws.model.price];
                [ws.headImage sd_setImageWithURL:[NSURL URLWithString:ws.model.pic]];
                ws.activityNameLab.text = self.model.title;
                ws.orderContentLab.text = self.model.message;
                ws.orderPriceLab.text = self.model.deposit;
                [ws.adImage sd_setImageWithURL:[NSURL URLWithString:ws.adModel.pic]];
                [ws.videoImage sd_setImageWithURL:[NSURL URLWithString:ws.model.video_pic]];
                NSString *str = ws.model.content;
                [ws.activityWeb loadHTMLString:str baseURL:nil];
                [ws.tableView reloadData];
            }else{
                [[HUDHelper sharedInstance] tipMessage:obj[@"msg"]];
            }
        }
    }];
}

- (void)adPicData{
    WS(ws)
    [[HttpRequest shardWebUtil] postNetworkRequestURLString:Url(@"/index/detailBottom") andParas:nil andTransferGottenData:^(id obj, NSError *error) {
        if (error) {
//            [[HUDHelper sharedInstance] tipMessage:obj[@"msg"]];
        }else{
            if ([obj[@"code"] integerValue] == 100000){
                ws.adModel = [AdModel yy_modelWithDictionary:obj[@"data"]];

            }else{
//                [[HUDHelper sharedInstance] tipMessage:obj[@"msg"]];
            }
        }
    }];
}

- (void)travelInforLikeBtnClick{
    NSDictionary * dic = @{
                           @"tid":@(self.activityId),
                           @"mid":[UserModel intance].member_id,
                           @"token":[UserModel intance].token,
                           @"type":@(2)
                           };
    [[HttpRequest shardWebUtil] postNetworkRequestURLString:Url(@"/index/collect") andParas:dic andTransferGottenData:^(id obj, NSError *error) {
        if (error) {
            [[HUDHelper sharedInstance] tipMessage:obj[@"msg"]];
        }else{
            if ([obj[@"code"] integerValue] == 100000){
                [[HUDHelper sharedInstance] tipMessage:obj[@"msg"]];
            }else{
                [[HUDHelper sharedInstance] tipMessage:obj[@"msg"]];
            }
        }
    }];
}


@end

@implementation ActivityDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.tableView];
    [self.view addSubview:self.bottomBarView];
    self.navigationController.delegate = self;
    
    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    [self getActivityDetail];

}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    if (self.navigationController.delegate == nil)
    {
        self.navigationController.delegate = self;
    }
    [self getActivityDetail];
}

#pragma mark - UINavigationControllerDelegate
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    BOOL isHomePage = [viewController isKindOfClass:[self class]];
    [self.navigationController setNavigationBarHidden:isHomePage animated:YES];
}

- (void)CRMediaPickerController:(CRMediaPickerController *)mediaPickerController didFinishPickingAsset:(ALAsset *)asset error:(NSError *)error
{
    
    if (!error)
    {
        if (asset)
        {
            if ([[asset valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto])
            {
                //图片
            }
            else if ([[asset valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo])
            {
                //视频
                ALAssetRepresentation *rep = [asset defaultRepresentation];
                Byte *buffer = (Byte*)malloc((NSUInteger)rep.size);
                NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:(NSUInteger)rep.size error:nil];
//                data = 视频数据
                NSData *data = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];
            }
        }
        else
        {
            NSLog(@"没选择");
        }
    }
    else
    {
        NSLog(@"%@", error.localizedDescription);
    }
}

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - bottomBarH)];
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.tableHeaderView = self.topView;
        _tableView.tableFooterView = self.footView;
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }return _tableView;
}

- (UIView *)topView{
    if (!_topView) {
        _topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 270)];
        _topView.backgroundColor = [UIColor whiteColor];
        
        UIView * borderView = [[UIView alloc] initWithFrame:CGRectMake(0, _topView.bottom - border, SCREEN_WIDTH, border)];
        borderView.backgroundColor = getColor(bgColor);
        [_topView addSubview:borderView];
        
        [self.topView addSubview:self.headImage];
        [self.topView addSubview:self.activityNameLab];
        [self.topView addSubview:self.moneyLab];
        
        UIButton *back = [[UIButton alloc]initWithFrame:CGRectMake(10, 20, 30, 30)];
        [back setImage:[UIImage imageNamed:@"icon_back2lwx"] forState:UIControlStateNormal];
        [back addTarget:self action:@selector(backClick:) forControlEvents:UIControlEventTouchUpInside];
        [_topView addSubview:back];
        
    }return _topView;
}

- (UIImageView *)headImage{
    if (!_headImage) {
        _headImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, headImageH)];
    }return _headImage;
}

- (UILabel *)activityNameLab{
    if (!_activityNameLab) {
        int activityY = self.headImage.bottom + border;
        int activityW = SCREEN_WIDTH - 2 * border;
        _activityNameLab = [[UILabel alloc] initWithFrame:CGRectMake(border, activityY, activityW, labelH)];
//        _activityNameLab.text = self.model.title;
        _activityNameLab.textColor = [UIColor blackColor];
        _activityNameLab.font = DEF_FontSize_14;
        _activityNameLab.textAlignment = NSTextAlignmentLeft;
    }return _activityNameLab;
}

- (UILabel *)moneyLab{
    if (!_moneyLab) {
        _moneyLab = [[UILabel alloc] initWithFrame:CGRectMake(self.activityNameLab.left, self.activityNameLab.bottom, self.activityNameLab.width, self.activityNameLab.height)];
        _moneyLab.textColor = [UIColor redColor];
        _moneyLab.font = DEF_FontSize_12;
        _moneyLab.textAlignment = NSTextAlignmentLeft;
    }return _moneyLab;
}

- (UIView *)footView{
    if (!_footView) {
        _footView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 300)];
//        _footView.backgroundColor = [UIColor redColor];
        UILabel * titleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, labelH)];
        titleLab.centerX = SCREEN_WIDTH / 2;
        titleLab.text = @"场景展示";
        titleLab.font = DEF_FontSize_14;
        titleLab.textAlignment = NSTextAlignmentCenter;
        [_footView addSubview:titleLab];

        int bottomContentW = SCREEN_WIDTH - 2 * border;
        self.videoImage = [[UIImageView alloc] initWithFrame:CGRectMake(border, titleLab.bottom, bottomContentW, headImageH)];
        self.videoImage.image = [UIImage imageNamed:@"img_list2111"];
        [_footView addSubview:self.videoImage];
        
        self.videoImageBtn = [[UIButton alloc] initWithFrame:self.videoImage.frame];
        self.videoImageBtn.backgroundColor = [UIColor clearColor];
        [self.videoImageBtn addTarget:self action:@selector(videoImageBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [_footView addSubview:self.videoImageBtn];
        
        UIView * videoLineView = [[UIView alloc] initWithFrame:CGRectMake(0, self.videoImage.bottom + border, SCREEN_WIDTH, 1)];
        videoLineView.backgroundColor = getColor(bgColor);
        [_footView addSubview:videoLineView];
        
        self.activityTitleLab = [[UILabel alloc] initWithFrame:titleLab.frame];
        self.activityTitleLab.top = videoLineView.bottom;
        self.activityTitleLab.text = @"活动详情";
        self.activityTitleLab.font = DEF_FontSize_14;
        self.activityTitleLab.textAlignment = NSTextAlignmentCenter;
        [_footView addSubview:self.activityTitleLab];
        
        CGFloat activityContentLabW = SCREEN_WIDTH - 2* border;
        //        首先是关键JS代码：
        NSString *jScript =
        @"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta); var imgs = document.getElementsByTagName('img');for (var i in imgs){imgs[i].style.maxWidth='100%';imgs[i].style.height='auto';}"
        ;
        //        然后初始化并加入JS片段：
        WKUserScript *wkUScript = [[WKUserScript alloc] initWithSource:jScript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
        WKUserContentController *wkUController = [[WKUserContentController alloc] init];
        [wkUController addUserScript:wkUScript];
        WKWebViewConfiguration *wkWebConfig = [[WKWebViewConfiguration alloc] init];
        wkWebConfig.userContentController = wkUController;
        self.activityWeb = [[WKWebView alloc] initWithFrame:CGRectMake(border, self.activityTitleLab.bottom, activityContentLabW, 0) configuration:wkWebConfig];
        self.activityWeb.scrollView.bounces = NO;
        self.activityWeb.scrollView.showsHorizontalScrollIndicator = NO;
        self.activityWeb.scrollView.scrollEnabled = NO;
        self.activityWeb.navigationDelegate = self;
        [_footView addSubview:self.activityWeb];
        
        self.activityLineView = [[UIView alloc] initWithFrame:videoLineView.frame];
        self.activityLineView.top = self.activityWeb.bottom + border;
        self.activityLineView.backgroundColor = getColor(bgColor);
        [_footView addSubview:self.activityLineView];
        
        self.orderTitleLab = [[UILabel alloc] initWithFrame:self.activityTitleLab.frame];
        self.orderTitleLab.top = self.activityLineView.bottom;
        self.orderTitleLab.text = @"套餐预定";
        self.orderTitleLab.font = DEF_FontSize_14;
        self.orderTitleLab.textAlignment = NSTextAlignmentCenter;
        [_footView addSubview:self.orderTitleLab];
        
        self.orderContentLab = [[UILabel alloc] initWithFrame:CGRectMake(border, self.orderTitleLab.bottom, SCREEN_WIDTH, 15)];
//        self.orderContentLab.text = @"傻大个三个收到是";
        self.orderContentLab.font = DEF_FontSize_12;
        self.orderContentLab.textAlignment = NSTextAlignmentLeft;
        [_footView addSubview:self.orderContentLab];
        
        self.orderPriceLab = [[UILabel alloc] initWithFrame:CGRectMake(border, self.orderContentLab.bottom, SCREEN_WIDTH, 15)];
//        self.orderPriceLab.text = @"246.00元";
        self.orderPriceLab.textColor = [UIColor redColor];
        self.orderPriceLab.font = DEF_FontSize_12;
        self.orderPriceLab.textAlignment = NSTextAlignmentLeft;
        [_footView addSubview:self.orderPriceLab];
        
        CGFloat orderBtnW = 60;
        CGFloat orderBtnH = 20;
        self.orderBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - orderBtnW - border, 0, orderBtnW, orderBtnH)];
        self.orderBtn.centerY = self.orderContentLab.bottom;
        [self.orderBtn setBackgroundColor:[UIColor orangeColor]];
        [self.orderBtn setTitle:@"预定" forState:UIControlStateNormal];
        self.orderBtn.titleLabel.font = DEF_FontSize_14;
        [self.orderBtn setCornerRadius:8];
        [self.orderBtn addTarget:self action:@selector(orderBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [_footView addSubview:self.orderBtn];
        
        self.adImage = [[UIImageView alloc] initWithFrame:CGRectMake(border, self.orderPriceLab.bottom + border, SCREEN_WIDTH - 2*border, headImageH / 2)];

        [self adPicData];
        self.adImage.userInteractionEnabled = YES;
        [_footView addSubview:self.adImage];
        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(adPageClick:)];
        tap.delegate = self;
        [self.adImage addGestureRecognizer:tap];
        
        _footView.frame = CGRectMake(0, 0, SCREEN_WIDTH, self.adImage.bottom + border);
    }return _footView;
}

- (UIView *)bottomBarView{
    if (!_bottomBarView) {
        int collectBtnW = 50;
        _bottomBarView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - bottomBarH, SCREEN_HEIGHT, bottomBarH)];
        _bottomBarView.backgroundColor = [UIColor orangeColor];
        self.collectBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, collectBtnW, _bottomBarView.height)];
        [self.collectBtn setImage:[UIImage imageNamed:@"icon_shoucang"] forState:UIControlStateNormal];
        [self.collectBtn setImage:[UIImage imageNamed:@"icon_yishoucang"] forState:UIControlStateSelected];
        [self.collectBtn addTarget:self action:@selector(collectBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.collectBtn setTitle:@"收藏" forState:UIControlStateNormal];
        CGFloat offset = 40.0f;
        self.collectBtn.titleEdgeInsets = UIEdgeInsetsMake(-15, -self.collectBtn.imageView.frame.size.width, -self.collectBtn.imageView.frame.size.height-offset/2, 0);
        self.collectBtn.imageEdgeInsets = UIEdgeInsetsMake(-self.collectBtn.titleLabel.intrinsicContentSize.height +5, -15, 0, -self.collectBtn.titleLabel.intrinsicContentSize.width);
        [self initButton:self.collectBtn];
        self.collectBtn.backgroundColor = [UIColor whiteColor];
        self.collectBtn.adjustsImageWhenHighlighted = NO;
        [_bottomBarView addSubview:self.collectBtn];
        
        self.serviceBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.collectBtn.right, 0, self.collectBtn.width, self.collectBtn.height)];
        [self.serviceBtn setImage:[UIImage imageNamed:@"icon_kefu"] forState:UIControlStateNormal];
        [self.serviceBtn addTarget:self action:@selector(serviceBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [self.serviceBtn setTitle:@"联系客服" forState:UIControlStateNormal];
        self.serviceBtn.backgroundColor = [UIColor yellowColor];
        
        self.serviceBtn.titleEdgeInsets = UIEdgeInsetsMake(-15, -self.serviceBtn.imageView.frame.size.width, -self.serviceBtn.imageView.frame.size.height-offset/2, 0);
        self.serviceBtn.imageEdgeInsets = UIEdgeInsetsMake(-self.serviceBtn.titleLabel.intrinsicContentSize.height + 8, -30, 0, -self.serviceBtn.titleLabel.intrinsicContentSize.width);
        [self initButton:self.serviceBtn];
        self.serviceBtn.backgroundColor = [UIColor whiteColor];
        [_bottomBarView addSubview:self.serviceBtn];
        
        self.addTravelBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.serviceBtn.right, 0, SCREEN_WIDTH - self.serviceBtn.right, self.collectBtn.height)];
        [self.addTravelBtn setTitle:@"加入行程" forState:UIControlStateNormal];
        [self.addTravelBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.addTravelBtn addTarget:self action:@selector(addTravelBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [self.addTravelBtn setBackgroundColor:getColor(@"ffbb02")];
        self.addTravelBtn.titleLabel.font = DEF_FontSize_16;
        self.addTravelBtn.adjustsImageWhenHighlighted = NO;
        [_bottomBarView addSubview:self.addTravelBtn];
        
    }return _bottomBarView;
}
-(void)initButton:(UIButton*)btn{
        btn.titleLabel.font = DEF_FontSize_10;
        [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    btn.backgroundColor = [UIColor whiteColor];
}

//自适应Lable长度
- (CGFloat)getWidthWithText:(NSString *)text height:(CGFloat)height font:(CGFloat)font{
    
    CGRect rect = [text boundingRectWithSize:CGSizeMake(MAXFLOAT, height)
                                     options:NSStringDrawingUsesLineFragmentOrigin
                                  attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:font]}
                                     context:nil];
    return rect.size.width;
}

//自适应Lable高度
- (CGFloat)getLabelHeightWithText:(NSString *)text width:(CGFloat)width font: (CGFloat)font
{
    CGRect rect = [text boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:font]} context:nil];
    
    return rect.size.height;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString * cellID = @"cell";
    [self.tableView registerClass:[ActivityDetailTableViewCell class] forCellReuseIdentifier:cellID];
    ActivityDetailTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
    if (!cell) {
        cell = [[ActivityDetailTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    if (indexPath.row == 0) {
        cell.titleLab.text = @"活动时间:";
        cell.contentLab.text = [NSString stringWithFormat:@"%@至%@", self.model.start_time, self.model.end_time];
        cell.imageView.image = [UIImage imageNamed:@"list_detail_duration"];
    }
    if (indexPath.row == 1) {
        cell.titleLab.text = @"报名截止时间:";
        cell.contentLab.text = [NSString stringWithFormat:@"%@", self.model.stop_time];
        cell.imageView.image = [UIImage imageNamed:@"list_detail_time"];
    }
    if (indexPath.row == 2) {
        cell.titleLab.text = @"活动地点:";
        cell.contentLab.text = [NSString stringWithFormat:@"%@", self.model.address];
        cell.imageView.image = [UIImage imageNamed:@"list_detail_location"];
    }
    if (indexPath.row == 3) {
        cell.titleLab.text = @"联系电话:";
        cell.contentLab.text = [NSString stringWithFormat:@"%@", self.model.tel];
        cell.imageView.image = [UIImage imageNamed:@"list_detail_tel"];
    }
    cell.delegate = self;
    return cell;
}

#pragma mark - action
- (void)collectBtnClick:(UIButton *)btn{
    NSLog(@"收藏");
    btn.selected = !btn.selected;
    [self travelInforLikeBtnClick];
}

- (void)orderBtnClick{
    NSLog(@"预定");
    if ([UserModel isSaveLogin]) {
        BookingInformationViewController * bookingInformationVC = [[BookingInformationViewController alloc] init];
        bookingInformationVC.reservationDeposit = self.orderPriceLab.text;
        bookingInformationVC.totalMoney = self.moneyLab.text;
        bookingInformationVC.type = @"2";
        bookingInformationVC.activityId = [NSString stringWithFormat:@"%i", self.activityId];
        [self.navigationController pushViewController:bookingInformationVC animated:YES];
    }else{
        [AppHelper showLogin];
    }
}

- (void)serviceBtnClick{
    NSLog(@"联系客服");
    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",@"10086"];
    UIWebView * callWebview = [[UIWebView alloc] init];
    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
    [self.view addSubview:callWebview];
}

- (void)adPageClick:(UITapGestureRecognizer *)tap{
    NSLog(@"跳转");
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:self.adModel.url]];
}

- (void)videoImageBtnClick{
    NSURL *url = [NSURL URLWithString:self.model.video];
    AVPlayer *avPlayer= [AVPlayer playerWithURL:url];
    if (@available(iOS 10.0, *)) {
        avPlayer.automaticallyWaitsToMinimizeStalling = NO;
    }
    AVPlayerViewController *playerViewController = [[AVPlayerViewController alloc] init];
    playerViewController.player = avPlayer;
    [[UIViewController getCurrentVC] presentViewController:playerViewController animated:YES completion:nil];
    [playerViewController.player play];
}

- (void)addTravelBtnClick{
    if ([UserModel isSaveLogin]) {
        BookingInformationViewController * bookingInformationVC = [[BookingInformationViewController alloc] init];
        bookingInformationVC.reservationDeposit = self.orderPriceLab.text;
        bookingInformationVC.totalMoney = self.moneyLab.text;
        bookingInformationVC.activityId = [NSString stringWithFormat:@"%i", self.activityId];
        bookingInformationVC.type = @"2";
        [self.navigationController pushViewController:bookingInformationVC animated:YES];
    }else{
        [AppHelper showLogin];
    }
}

- (void)backClick:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
    WS(ws)
    [webView evaluateJavaScript:@"document.body.offsetHeight;" completionHandler:^(id _Nullable any, NSError * _Nullable error) {
        NSString *heightStr = [NSString stringWithFormat:@"%@",any];
        ws.activityWeb.frame = CGRectMake(border, ws.activityTitleLab.bottom, ws.view.frame.size.width - 20, heightStr.floatValue + 10);
        ws.activityLineView.top = ws.activityWeb.bottom;
        ws.orderTitleLab.top = ws.activityWeb.bottom;
        ws.orderContentLab.top = ws.orderTitleLab.bottom;
        ws.orderPriceLab.top = ws.orderContentLab.bottom;
        ws.orderBtn.centerY = ws.orderContentLab.bottom;
        ws.adImage.top = ws.orderPriceLab.bottom + border;
        ws.footView.frame = CGRectMake(0, 0, SCREEN_WIDTH, self.adImage.bottom + border);
        [ws.tableView reloadData];
    }];

}

@end
